import { createRouter, createWebHashHistory } from "vue-router";
import routes from "@/router/routes.js";
import { showFailToast } from "vant";
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;

//全局路由守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("token");
  if (token && to.path === "/login") {
    showFailToast("您已登录，请勿重复登录！");
    return next({
      path: from.path ? from.path : "/home",
    });
  }
  next();
});
